package com.xzx.mr.order2;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * @author xinzhixuan
 * @version V1.0
 * @date 2019/7/21 22:29
 */
public class OrderSortGroupingComparator extends WritableComparator {

    public OrderSortGroupingComparator() {
        // 注意，这里只能传true，不然会发生NPE异常
        super(OrderBean.class, true);
    }
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        OrderBean aOrderBean = (OrderBean) a;
        OrderBean bOrderBean = (OrderBean) b;
        if (aOrderBean.getId() > bOrderBean.getId()) {
            return 1;
        } else if (aOrderBean.getId() < bOrderBean.getId()) {
            return -1;
        } else {
            return 0;
        }
    }
}
